package com.example.educationai.service.impl;

import com.example.educationai.entity.Exam;
import com.example.educationai.entity.ClassEntity;
import com.example.educationai.entity.SimpleUser;
import com.example.educationai.repository.ExamRepository;
import com.example.educationai.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ExamServiceImpl implements ExamService {

    @Autowired
    private ExamRepository examRepository;

    @Override
    public Exam createExam(Exam exam) {
        return examRepository.save(exam);
    }

    @Override
    public Exam updateExam(Exam exam) {
        return examRepository.save(exam);
    }

    @Override
    public void deleteExam(Long id) {
        examRepository.deleteById(id);
    }

    @Override
    public Exam getExam(Long id) {
        return examRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("考试不存在"));
    }

    @Override
    public List<Exam> getClassEntityExams(ClassEntity classEntity) {
        return examRepository.findByClassEntity(classEntity);
    }

    @Override
    public List<Exam> getClassEntityExamsOrderByDate(ClassEntity classEntity) {
        return examRepository.findByClassEntityOrderByExamDateDesc(classEntity);
    }

    @Override
    public List<Exam> getStudentExams(SimpleUser student) {
        return examRepository.findByStudent(student);
    }

    @Override
    public List<Exam> getTeacherExams(SimpleUser teacher) {
        return examRepository.findByTeacher(teacher);
    }

    @Override
    public List<Exam> findByTeacherId(Long teacherId) {
        return examRepository.findByTeacherId(teacherId);
    }

    @Override
    public Exam save(Exam exam) {
        return examRepository.save(exam);
    }
} 